/*
 * ActionComponentDelegate.h  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef ACTIONCOMPONENTDELEGATE_H
#define ACTIONCOMPONENTDELEGATE_H

#include "Cute4jSwing.h"

#include "ComponentDelegate.h"

// ActionComponentDelegate Class. ----------------------------------------------

// TODO: test entire module and add better QAction-QWidget switching support

/*!
 * \brief QAction-Component Data.
 * 
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT ActionComponentData
{
  friend class ActionComponentDelegate; // uses all members
protected:
  ActionComponentData();
public:
  // TODO: implement getters
protected:
  bool focusable;
  bool opaque;
  bool updatesEnabled;
  int orientation;
  QRect bounds;
  QSize maximumSize;
  QSize minimumSize;
  QSize fixedSize;
  QColor background;
  QColor foreground;
  QString toolTip;
  QString styleSheet;
  QCursor cursor;
};

// ActionComponentDelegate Class. ----------------------------------------------

/*!
 * \brief QAction-Component Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class ActionComponentDelegate : public ComponentDelegate
{
  Q_OBJECT
protected:
  ActionComponentDelegate(JNIEnv *env, jobject obj, QAction *action);
  ActionComponentDelegate(JNIEnv *env, jobject obj);
  virtual ~ActionComponentDelegate();
public slots: // native calls
  virtual void setVisible(JNIEnv *env, jboolean visible);
  virtual void showWindow(JNIEnv *env);
  virtual void setEnabled(JNIEnv *env, jboolean enabled);
  virtual void setFocusable(JNIEnv *env, jboolean focusable);
  virtual void requestFocus(JNIEnv *env);
  virtual void setLocation(JNIEnv *env, jint x, jint y);
  virtual jobject getPreferredSize(JNIEnv *env);
  virtual void setSize(JNIEnv *env, jint width, jint height);
  virtual void setMaximumSize(JNIEnv *env, jint width, jint height);
  virtual void setMinimumSize(JNIEnv *env, jint width, jint height);
  virtual void setFixedSize(JNIEnv *env, jint width, jint height);
  virtual void setBounds(JNIEnv *env, jint x, jint y, jint width, jint height);
  virtual jobject getBackground(JNIEnv *env, jclass colorClass);
  virtual void setBackground(JNIEnv *env, jint argb);
  virtual void setNullBackground(JNIEnv *env);
  virtual jobject getForeground(JNIEnv *env, jclass colorClass);
  virtual void setForeground(JNIEnv *env, jint argb);
  virtual void setNullForeground(JNIEnv *env);
  virtual void setOpaque(JNIEnv *env, jboolean opaque);
  virtual jobject getFont(JNIEnv *env, jclass fontClass);
  virtual void setFont(JNIEnv *env, jobject font);
  virtual void setStyleSheet(JNIEnv *env, jstring styleSheetText);
  virtual jint getCursor(JNIEnv *env);
  virtual void setCursor(JNIEnv *env, jint type);
  virtual void repaint(JNIEnv *env);
  virtual void repaint(JNIEnv *env, jint x, jint y, jint width, jint height);
  virtual void update(JNIEnv *env);
  virtual void update(JNIEnv *env, jint x, jint y, jint width, jint height);
  virtual void setUpdatesEnabled(JNIEnv *env, jboolean enabled);
  virtual void polish(JNIEnv *env);
  virtual void setComponentOrientation(JNIEnv *env, jint orientation);
  virtual void setToolTipText(JNIEnv *env, jstring text);
  virtual void setStatusTipText(JNIEnv *env, jstring text);
  virtual void setWhatsThisText(JNIEnv *env, jstring text);
public:
  virtual void setParentDelegate(ContainerDelegate *parentDelegate);
  virtual QWidget *qWidget();
  virtual QAction *qAction();
protected:
  virtual QWidget *createQWidget() = 0;
  virtual QAction *createQAction() = 0;
protected:
  virtual void deleteQWidget(QWidget *widget);
  virtual void deleteQAction(QAction *action);
  virtual void switchToQWidget();
  virtual void switchToQAction();
  virtual QWidget *convertToQWidget(QAction *action);
  virtual QAction *convertToQAction(QWidget *widget);
  virtual ActionComponentData *createActionData();
protected:
  virtual void filterEnabledEvents();
protected:
  bool isQWidget();
  ActionComponentData *actionData();
  ActionComponentData *getActionData(QAction *action);
protected:
  inline QWidget *widget() const;
  inline QAction *action() const;
protected:
  virtual void objectDestroyed(QObject *qObj);
private:
  bool m_makeVisible;
};

// ActionComponentDelegate :: Protected Inline Member Functions. ---------------

/*!
 * \brief Returns widget data member.
 *
 * \return widget data member
 */
inline QWidget *ActionComponentDelegate::widget() const
{
  return m_widget;
}

/*!
 * \brief Returns action data member.
 *
 * \return action data member
 */
inline QAction *ActionComponentDelegate::action() const
{
  return m_action;
}

#endif // ACTIONCOMPONENTDELEGATE_H
